package com.zuqiuzhandui.liveing.view.streaming;

import android.content.Context;

import com.code19.library.L;
import com.zuqiuzhandui.liveing.model.resultModel.LiveNumberQtyRs;
import com.zuqiuzhandui.liveing.net.HttpMethods;
import com.zuqiuzhandui.liveing.net.ProgressSubscriber;
import com.zuqiuzhandui.liveing.net.SubscriberOnNextListener;
import com.zuqiuzhandui.liveing.net.UrlFactory;

import java.util.Map;

import rx.Subscriber;

/**
 * Created by yq on 2016-10-10.
 */

public class StreamingPresenter implements StreamContract.Presenter{
        StreamContract.View mView;

    public StreamingPresenter(StreamContract.View mView) {
        this.mView = mView;
        this.mView.setPresenter(this);
    }

    @Override
    public void requestInform(String code) {
        Map<String,String> map=UrlFactory.getAccessKeyMap();
        map.put("code",code);
            HttpMethods.getInstance().postNotify(new ProgressSubscriber<Integer>(new SubscriberOnNextListener<Integer>() {
                @Override
                public void onNext(Integer o) {
                    if (!mView.isActive()) {
                        return;
                    }
                    mView.showSuccessInform();
                }
            }, (Context) mView),map);

    }

    @Override
    public void requestLiveNumber(String code) {
        Map<String,String> map= UrlFactory.getAccessKeyMap();
        map.put("code",code);
        HttpMethods.getInstance().postLiveNumberQty(new Subscriber<LiveNumberQtyRs>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(LiveNumberQtyRs liveNumberQtyRs) {
                if (!mView.isActive()) {
                    return;
                }
                L.d("获取的在线人数是"+liveNumberQtyRs.getCurOnlineMember());
                mView.showSuccessLiveNumber(liveNumberQtyRs);
            }
        },map);
    }


}
